package org.example.day20240828;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class birthday {

    public static String leftPadding(String str){
        StringBuilder strBuilder = new StringBuilder(str);
        for (int i = 0; i< strBuilder.length(); i++){
            if(4- strBuilder.length()>0){
                strBuilder.insert(0, "0");
            }
        }
        str = strBuilder.toString();
        return str;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num1 = scanner.nextInt();
        int num2 = scanner.nextInt();
        int year = 0;
        while (true){
            Set<Integer> birSet = new HashSet<>();
            if(num1 > 999){
                int Num1 = num1/1000;
                int Num2 = num1/100%10;
                int Num3 = num1/10%10;
                int Num4 = num1%10;
                birSet.add(Num1);
                birSet.add(Num2);
                birSet.add(Num3);
                birSet.add(Num4);
            } else if (num1 >99) {
                int Num2 = num1/100%10;
                int Num3 = num1/10%10;
                int Num4 = num1%10;
                birSet.add(0);
                birSet.add(Num2);
                birSet.add(Num3);
                birSet.add(Num4);
            }else if(num1 >9){
                birSet.add(0);
                int Num3 = num1/10%10;
                int Num4 = num1%10;
                birSet.add(Num3);
                birSet.add(Num4);
            }else {
                birSet.add(0);
                birSet.add(num1);
            }
            if(birSet.size() == num2){
                break;
            }
            num1++;
            year++;
        }
        String result = leftPadding(String.valueOf(num1));
        System.out.println(year+" "+result);
    }
}
